package com.wlsk.license.common.utils;

import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.DataSourceConfig;
import com.baomidou.mybatisplus.generator.config.OutputFile;
import com.baomidou.mybatisplus.generator.config.TemplateType;

import java.util.HashMap;
import java.util.Map;

public class CodeGenerator {

    public static void main(String[] args) {
        String projectPath = System.getProperty("user.dir");
        String modulePath = "/charteredLicense-service";
        Map<OutputFile, String> pathInfo = new HashMap<>();
        pathInfo.put(OutputFile.xml, projectPath + modulePath + "/src/main/resources/mapper/");
        FastAutoGenerator.create(new DataSourceConfig
                        .Builder("jdbc:mysql://192.168.3.111:3306/charteredlicense?useUnicode=true&characterEncoding=utf-8&allowMultiQueries=true",
                        "dbkf",
                        "Jdn#1udg#1h"))
                // 全局配置
                .globalConfig((scanner, builder) -> builder.author("admin")
                        .outputDir(System.getProperty("user.dir")+modulePath+"/src/main/java").disableOpenDir().enableSwagger())
                // 包配置
                .packageConfig((scanner, builder) -> builder.parent("com.wlsk.license")
                        .pathInfo(pathInfo)
                        .service("service")
                        .serviceImpl("service.serviceImpl")
                        .mapper("dao.mapper")
                        .xml("mapper")
                        .entity("dao.entity"))
                .templateConfig((scanner, builder) -> builder.disable(TemplateType.CONTROLLER))
                // 策略配置
                .strategyConfig((scanner, builder) -> builder
                       // .addExclude("添加需要生成的表")
                        .addTablePrefix("cl")
                        .addInclude("cl_channel_order")
                        .controllerBuilder().enableRestStyle().enableHyphenStyle().entityBuilder().enableTableFieldAnnotation()
                        .entityBuilder().enableLombok().build()).execute();
    }
}